require 'fiddle'
require 'net/http'
require 'uri'
require 'time'
load 'facecat.rb'

$gPaint = FCPaint.new()
$gPaint.defaultUIStyle = "dark"
$latestDataStr = ""
$gridStocks = nil
$findMyCharts = []
$charts = []

#绘制买卖档
#view:视图
#paint:绘图对象
#clipRect:区域
def drawLatestDiv(view, paint, clipRect)
	avgHeight = 20
	drawFont = "Default,14"
	dTop = 30
	paint.drawLine(view.borderColor, 1, 0, 0, dTop, view.size.cx, dTop)
	dataStrs = $latestDataStr.split(",")
	lastClose = 0
	priceList = []
	volList = []
	buySellTexts = []
	if dataStrs.length > 10
		paint.drawText(dataStrs[0], "rgb(175,196,228)", "Default,14", 5, 7)
		paint.drawText(dataStrs[1], "rgb(194,151,18)", "Default,14", 80, 7)
		lastClose = dataStrs[8].to_f
		priceList.append(dataStrs[23].to_f)
		priceList.append(dataStrs[22].to_f)
		priceList.append(dataStrs[21].to_f)
		priceList.append(dataStrs[20].to_f)
		priceList.append(dataStrs[19].to_f)
		priceList.append(dataStrs[9].to_f)
		priceList.append(dataStrs[10].to_f)
		priceList.append(dataStrs[11].to_f)
		priceList.append(dataStrs[12].to_f)
		priceList.append(dataStrs[13].to_f)

		volList.append(dataStrs[28].to_f)
		volList.append(dataStrs[27].to_f)
		volList.append(dataStrs[26].to_f)
		volList.append(dataStrs[25].to_f)
		volList.append(dataStrs[24].to_f)
		volList.append(dataStrs[14].to_f)
		volList.append(dataStrs[15].to_f)
		volList.append(dataStrs[16].to_f)
		volList.append(dataStrs[17].to_f)
		volList.append(dataStrs[18].to_f)
	end
	buySellTexts.append("卖5")
	buySellTexts.append("卖4")
	buySellTexts.append("卖3")
	buySellTexts.append("卖2")
	buySellTexts.append("卖1")
	buySellTexts.append("买1")
	buySellTexts.append("买2")
	buySellTexts.append("买3")
	buySellTexts.append("买4")
	buySellTexts.append("买5")
	textColor = "rgb(175,196,228)"
	if view.paint.defaultUIStyle == "light"
		textColor = "rgb(0,0,0)"
	end
	maxVol = maxValue(volList)
	for i in 0..9
		tSize = paint.textSize(buySellTexts[i], drawFont)
		paint.drawText(buySellTexts[i], textColor, drawFont, 5, dTop + avgHeight / 2 - tSize.cy / 2)
		if priceList.length > 0
			price = priceList[i]
			upDownColor = "rgb(255,82,82)"
			upDownColor2 = "rgb(50,0,0)"
			if price < lastClose
				upDownColor = "rgb(46,255,50)"
				upDownColor2 = "rgb(0,50,0)"
			end
			paint.drawText(toFixed(priceList[i], 2), upDownColor, drawFont, 50, dTop + avgHeight / 2 - tSize.cy / 2)
			if maxVol > 0
				paint.fillRect(upDownColor2, view.size.cx - volList[i] * 80 / maxVol, dTop + 2, view.size.cx, dTop + avgHeight - 2)
			end
			volText = toFixed(volList[i] / 100, 0)
			volTextSize = paint.textSize(volText, drawFont)
			paint.drawText(volText, textColor, drawFont, view.size.cx - volTextSize.cx - 10, dTop + avgHeight / 2 - volTextSize.cy / 2)
		end
		dTop += avgHeight
	end
	paint.drawLine(view.borderColor, 1, 0, 0, dTop, view.size.cx, dTop)
	paint.drawText("现价", "rgb(175,196,228)", drawFont, 5, dTop + 10)
	paint.drawText("幅度", "rgb(175,196,228)", drawFont, 5, dTop + 35)
	paint.drawText("总额", "rgb(175,196,228)", drawFont, 5, dTop + 60)
	paint.drawText("总量", "rgb(175,196,228)", drawFont, 5, dTop + 85)
	paint.drawText("开盘", "rgb(175,196,228)", drawFont, 110, dTop + 10)
	paint.drawText("振幅", "rgb(175,196,228)", drawFont, 110, dTop + 35)
	paint.drawText("最高", "rgb(175,196,228)", drawFont, 110, dTop + 60)
	paint.drawText("最低", "rgb(175,196,228)", drawFont, 110, dTop + 85)
	if dataStrs.length > 10
		close = dataStrs[2].to_f
		high = dataStrs[3].to_f
		low = dataStrs[4].to_f
		openPrice = dataStrs[5].to_f
		volume = dataStrs[6].to_f
		amount = dataStrs[7].to_f
		diff = 0
		if lastClose > 0
			diff = 100 * (close - lastClose) / lastClose
		end
		diff2 = 0
		if lastClose > 0
			diff2 = 100 * (high - lastClose) / lastClose - 100 * (low - lastClose) / lastClose
		end
		paint.drawText(toFixed(close, 2), getPriceColor(close, lastClose), drawFont, 40, dTop + 10)
		paint.drawText(toFixed(diff, 2) + "%", getPriceColor(close, lastClose), drawFont, 40, dTop + 35)
		paint.drawText(toFixed(amount / 10000, 0), textColor, drawFont, 40, dTop + 60)
		paint.drawText(toFixed(volume / 10000, 0), textColor, drawFont, 40, dTop + 85)

		paint.drawText(toFixed(openPrice, 2), getPriceColor(openPrice, lastClose), drawFont, 150, dTop + 10)
		paint.drawText(toFixed(diff2, 2) + "%", getPriceColor(close, lastClose), drawFont, 150, dTop + 35)
		paint.drawText(toFixed(high, 2), getPriceColor(high, lastClose), drawFont, 150, dTop + 60)
		paint.drawText(toFixed(low, 2), getPriceColor(low, lastClose), drawFont, 150, dTop + 85)
	end
end

#黑色风格
def toBlackChart(chart, index)
	chart.paint.defaultUIStyle = "dark"
	chart.backColor = "rgb(0,0,0)"
	chart.borderColor = "none"
	chart.textColor = "rgb(175,196,228)"
	chart.scaleColor = "rgb(75,75,75)"
	chart.crossTipColor = "rgb(50,50,50)"
	chart.crossLineColor = "rgb(100,100,100)"
	chart.gridColor = "rgb(50,50,50)"
	if index > 0
		chart.upColor = "rgb(186,56,18)"
		chart.downColor = "rgb(31,182,177)"
	else
		chart.upColor = "rgb(255,82,82)"
		chart.downColor = "rgb(46,255,50)"
	end
	chart.barStyle = "rect2"
	chart.candleStyle = "rect2"
	chart.trendColor = "rgb(255,255,255)"
	chart.hScaleTextColor = "rgb(194,151,18)"
	chart.vScaleTextColor = "rgb(194,151,18)"
end

#获取价格颜色
def getPriceColor(price, comparePrice)
	if price != 0
		if price > comparePrice
			return "rgb(255,82,82)"
		elsif price < comparePrice
			return "rgb(46,255,50)"
		end
	end
	return "rgb(190,190,235)"
end

#查找同类型视图
def findViewsByType(findType, views, refViews)
	size = views.length
	for i in 0..size - 1
		view = views[i]
		if view.viewType == findType
			refViews.append(view)
		elsif view.views.length > 0
			findViewsByType(findType, view.views, refViews)
		end
	end
end

#请求报价
def queryPrice(codes)
	url = "http://110.42.188.197:9968/quote?func=price&count=500&codes=" + codes
	uri = URI(url)
	response = Net::HTTP.get_response(uri)
	result = response.body
	strs = result.split("\r\n")
	for i in 0..strs.length - 1
		subStrs = strs[i].split(",")
		if subStrs.length >= 15
			row = FCGridRow.new()
			$gridStocks.rows.append(row)
			cell1 = createGridCell($gridStocks)
			cell1.value = i
			row.cells.append(cell1)

			cell2 = createGridCell($gridStocks)
			cell2.value = subStrs[0]
			cell2.textColor = "rgb(194,151,18)"
			row.cells.append(cell2)

			cell3 = createGridCell($gridStocks)
			cell3.value = subStrs[1]
			row.cells.append(cell3)

			close = subStrs[2].to_f
			high = subStrs[3].to_f
			low =  subStrs[4].to_f
			lastClose = subStrs[8].to_f
			cell4 = createGridCell($gridStocks)
			cell4.value = toFixed(close, 2)
			cell4.textColor = getPriceColor(close, lastClose)
			row.cells.append(cell4)
			diff = 0
			if lastClose > 0
				diff = 100 * (close - lastClose) / lastClose
			end
			cell5 = createGridCell($gridStocks)
			cell5.value = toFixed(diff, 2) + "%"
			cell5.textColor = getPriceColor(diff, 0)
			row.cells.append(cell5)

			cell6 = createGridCell($gridStocks)
			cell6.value = toFixed(close - lastClose, 2)
			cell6.textColor = getPriceColor(close, lastClose)
			row.cells.append(cell6)

			volume = subStrs[6].to_f
			amount = subStrs[7].to_f
			cell7 = createGridCell($gridStocks)
			cell7.value = toFixed(volume / 100 / 10000, 2) + "万"
			row.cells.append(cell7)

			cell8 = createGridCell($gridStocks)
			cell8.value = toFixed(amount / 100000000, 2) + "亿"
			row.cells.append(cell8)

			cell9 = createGridCell($gridStocks)
			cell9.value = toFixed(subStrs[12].to_f, 2)
			row.cells.append(cell9)

			cell10 = createGridCell($gridStocks)
			cell10.value = toFixed(subStrs[11].to_f, 2)
			row.cells.append(cell10)

			diff2 = 0
			if lastClose > 0
				diff2 = 100 * (high - lastClose) / lastClose - 100 * (low - lastClose) / lastClose
			end
			cell11 = createGridCell($gridStocks)
			cell11.value = toFixed(diff2, 2) + "%"
			row.cells.append(cell11)

			cell12 = createGridCell($gridStocks)
			cell12.value = toFixed(subStrs[13].to_f, 2)
			row.cells.append(cell12)

			marketValue = subStrs[9].to_f * close
			cell13 = createGridCell($gridStocks)
			cell13.value = toFixed(marketValue / 100000000, 2) + "亿"
			row.cells.append(cell13)

			flowValue = subStrs[10].to_f * close
			cell14 = createGridCell($gridStocks)
			cell14.value = toFixed(flowValue / 100000000, 2) + "亿"
			row.cells.append(cell14)

			cell15 = createGridCell($gridStocks)
			cell15.value = ""
			row.cells.append(cell15)

			upperLimit = subStrs[14].to_f
			lowerLimit = subStrs[15].to_f
			cell16 = createGridCell($gridStocks)
			cell16.value = toFixed(upperLimit, 2)
			cell16.textColor = getPriceColor(1, 0)
			row.cells.append(cell16)

			cell17 = createGridCell($gridStocks)
			cell17.value = toFixed(lowerLimit, 2)
			cell17.textColor = getPriceColor(0, 1)
			row.cells.append(cell17)

			cell18 = createGridCell($gridStocks)
			cell18.value = ""
			row.cells.append(cell18)

			cell19 = createGridCell($gridStocks)
			cell19.value = ""
			row.cells.append(cell19)

			cell20 = createGridCell($gridStocks)
			cell20.value = ""
			row.cells.append(cell20)

			cell21 = createGridCell($gridStocks)
			cell21.value = ""
			row.cells.append(cell21)

			cell22 = createGridCell($gridStocks)
			cell22.value = ""
			row.cells.append(cell22)
		end
	end
	invalidateView($gridStocks)
end

#请求历史数据
def queryHistoryData(mychart, chart, code)
	strCycle = mychart.exAttributes["cycle"]
	intCycle = strCycle.to_i
	url = "http://110.42.188.197:9968/quote?func=getkline&code=" + code +  "&cycle=" + strCycle + "&count=500"
	if intCycle == 0
		url = "http://110.42.188.197:9968/quote?func=getkline&code=" + code +  "&cycle=0&count=240"
	end
	uri = URI(url)
	response = Net::HTTP.get_response(uri)
	result = response.body
	dataList = []
	strs = result.split("\r\n")
	chart.firstOpen = 0
	if intCycle == 0
		fStrs = strs[0].split(" ")
		if fStrs.length >= 3
			chart.firstOpen = fStrs[2].to_f
		end
	end
	for i in 2..strs.length - 1
		subStrs = strs[i].split(",")
		if subStrs.length >= 7
			data = SecurityData.new()
			if intCycle < 1440
				dateStr = subStrs[0] + " " + subStrs[1][0..1] + ":" + subStrs[1][2..3] + ":00"
				data.open = subStrs[2].to_f
				data.high = subStrs[3].to_f
				data.low = subStrs[4].to_f
				data.close = subStrs[5].to_f
				data.volume = subStrs[6].to_f
				data.date = Time.parse(dateStr).to_i
				if intCycle == 0 && (data.volume > 0 || dataList.count == 0)
					chart.lastValidIndex = dataList.length
					if chart.firstOpen == 0
						chart.firstOpen = data.close
					end
				end
			else
				data.open = subStrs[1].to_f
				data.high = subStrs[2].to_f
				data.low = subStrs[3].to_f
				data.close = subStrs[4].to_f
				data.volume = subStrs[5].to_f
				dateStr = subStrs[0]
				data.date = Time.parse(dateStr).to_i
			end
			dataList.append(data)
		end
	end
	if intCycle == 0
		chart.autoFillHScale = true
		chart.cycle = "trend"
	elsif intCycle < 1440
		chart.cycle = "minute"
	else
		chart.cycle = "day"
	end
	chart.datas = dataList
	maxVisibleRecord = getChartMaxVisibleCount(chart, chart.hScalePixel, getChartWorkAreaWidth(chart))
	chart.lastVisibleIndex = chart.datas.length - 1
	if maxVisibleRecord > chart.datas.length
		chart.firstVisibleIndex = 0
	else
		chart.firstVisibleIndex = chart.lastVisibleIndex - maxVisibleRecord + 1
	end
	resetChartVisibleRecord(chart)
	checkChartLastVisibleIndex(chart)
	calcChartIndicator(chart)
	invalidateView(chart)
end

#请求最新数据
def queryNewData(code)
	url = "http://110.42.188.197:9968/quote?func=getnewdata&codes=" + code
	uri = URI(url)
	response = Net::HTTP.get_response(uri)
	result = response.body
	$latestDataStr = result
	invalidate($gPaint)
end

#创建单元格
def createGridCell (grid)
	gridCell = FCGridCell.new()
	if grid.paint.defaultUIStyle == "dark"
		gridCell.backColor = "none"
		gridCell.borderColor = "none"
		gridCell.textColor = "rgb(175,196,228)"
	elsif grid.paint.defaultUIStyle == "light"
		gridCell.backColor = "none"
		gridCell.borderColor = "none"
		gridCell.textColor = "rgb(0,0,0)"
	end
	gridCell.font = "Default,13"
	return gridCell
end

#视图的鼠标按下方法
#view 视图
#mp 坐标
#buttons 按钮 0未按下 1左键 2右键
#clicks 点击次数
#delta 滚轮值
$gPaint.onPaint = Proc.new do|view, paint, clipRect|
	if view.viewType == "latestdiv"
		drawLatestDiv(view, paint, clipRect)
	else
		onPaintDefault(view, paint, clipRect)
	end
end

#视图的鼠标点击方法
#grid 表格
#row 行
#gridColumn 列
#cell单元格
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks:点击次数
$gPaint.onClickGridCell = Proc.new do|grid, row, gridColumn, cell, firstTouch, firstPoint, secondTouch, secondPoint, clicks|
	code = row.cells[1].value
	name = row.cells[2].value
	for i in 0..$findMyCharts.length - 1
		myChart = $findMyCharts[i]
		chart = $charts[i]
		chart.text = code + " " + name
		queryHistoryData(myChart, chart, code)
		if i >= 2
			break
		end
	end
	queryNewData(code)
	invalidate(grid.paint)
end

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks:点击次数
$gPaint.onClick = Proc.new do|view, firstTouch, firstPoint, secondTouch, secondPoint, clicks|
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)
	if view.viewName.include?("cycle,")
		strs = view.viewName.split(",")
		index = strs[1].to_i
		cycleInt = strs[2].to_i
		$findMyCharts[index].exAttributes["cycle"] = cycleInt.to_s
		queryHistoryData($findMyCharts[index], $charts[index], $charts[index].text.split(" ")[0])
	end
end

WndProc = Fiddle::Closure::BlockCaller.new(Fiddle::TYPE_VOID, [Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]) do |hWnd, message, wParam, lParam|
	WndProcDefault($gPaint, hWnd, message, wParam, lParam)	
end
$registerWndProc = Fiddle::Function.new(
  $facecat['registerWndProc'],
  [Fiddle::TYPE_VOIDP],
  Fiddle::TYPE_VOID
)
initWindow()
$registerWndProc.call(WndProc.to_i)
createWindow($gPaint)
xml = '''<?xml version="1.0" encoding="utf-8" ?>
        <html xmlns="facecat">
        <body>
            <div bordercolor="none" name="divInner" dock="fill">
                <div type="tab" dock="fill" selectedindex="0" backcolor="none" bordercolor="none"
                name="tabFunc">
                    <div type="tabpage" text="主界面" name="divMain" backcolor="none">
                    <div type="splitlayout" layoutstyle="lefttoright" bordercolor="none" dock="fill"
                            size="650,510" candragsplitter="true" splitterposition="650,1" name="divCodingRight2">
                            <table name="gridStocks" headerheight="30" dock="fill"
                                gridlinecolor="none" bordercolor="none" showvscrollbar="true" showhscrollbar="true"
                                allowpreviewsevent="true" allowdragscroll="true">
                                <tr>
                                    <th name="colP0" text="序" width="40" allowdrag="true" allowresize="true"/>
                                    <th name="colP1" text="代码" width="70" allowdrag="true" allowresize="true"/>
                                    <th name="colP2" text="名称" width="70" allowdrag="true" allowresize="true" />
                                    <th name="colP3" text="现价" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP4" text="涨幅" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP5" text="涨跌" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP9" text="总量" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP10" text="总额" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP11" text="量比" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP12" text="PE动" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP13" text="振幅" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP14" text="换手率" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP15" text="总市值" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP16" text="流值" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP17" text="行业分类板块" width="80" allowdrag="true" allowresize="true" cellalign="center"/>
                                    <th name="colP18" text="涨停价" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP19" text="跌停价" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP20" text="金比" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP21" text="涨跌比" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP22" text="涨速" width="60" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP23" text="净资产收益率" width="100" allowdrag="true" allowresize="true" cellalign="right"/>
                                    <th name="colP24" text="自设指标" width="80" allowdrag="true" allowresize="true" cellalign="right"/>
                                </tr>
                            </table>
                            <div type="splitlayout" layoutstyle="toptobottom" bordercolor="none" dock="fill"
                                size="400,400" candragsplitter="true" splitterposition="380,1">
                                <div type="splitlayout" layoutstyle="righttoleft" bordercolor="none" dock="fill"
                                    size="400,400" candragsplitter="true" splitterposition="200,1">
                                    <div type="custom" cid="latestdiv" name="divLatest"/>
                                    <div type="custom" cid="mychart" name="mainChart1" cycle="0" candledivpercent="0.7"
                                            voldivpercent="0.3" backcolor="none" bordercolor="none"/>
                                </div>
                                <div type="splitlayout" layoutstyle="lefttoright" bordercolor="none" dock="fill"
                                    size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="200,1">
                                    <div type="custom" cid="mychart" name="mainChart2" cycle="5" candledivpercent="0.7"
                                            voldivpercent="0.3" backcolor="none" bordercolor="none"/>
                                    <div type="custom" cid="mychart" name="mainChart3" cycle="1440" candledivpercent="0.7"
                                            voldivpercent="0.3" backcolor="none" bordercolor="none"/>
                                </div>
                            </div>
                        </div>
                        </div>
                        <div type="tabpage" text="多K线" name="divMulti" backcolor="none">
                            <div type="splitlayout" layoutstyle="lefttoright" backcolor="none" bordercolor="none"
                                dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="133,1">
                                <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                    dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="267,1">
                                    <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                        dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="200,1">
                                        <div type="custom" cid="mychart" name="chart1" cycle="1" nativerefresh="true" candledivpercent="1"
                                            voldivpercent="0" backcolor="none" bordercolor="none"/>
                                        <div type="custom" cid="mychart" name="chart2" cycle="5" nativerefresh="true" candledivpercent="1"
                                            voldivpercent="0" backcolor="none" bordercolor="none"/>
                                    </div>
                                    <div type="custom" cid="mychart" name="chart3" cycle="10" nativerefresh="true" candledivpercent="1"
                                        voldivpercent="0" backcolor="none" bordercolor="none"/>
                                </div>
                                <div type="splitlayout" layoutstyle="lefttoright" backcolor="none" bordercolor="none"
                                    dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="200,1">
                                    <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                        dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="267,1">
                                        <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                            dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="200,1">
                                            <div type="custom" cid="mychart" name="chart4" cycle="15" nativerefresh="true" candledivpercent="1"
                                                voldivpercent="0" backcolor="none" bordercolor="none"/>
                                            <div type="custom" cid="mychart" name="chart5" cycle="20" nativerefresh="true" candledivpercent="1"
                                                voldivpercent="0" backcolor="none" bordercolor="none"/>
                                        </div>
                                        <div type="custom" cid="mychart" name="chart6" cycle="30" nativerefresh="true" candledivpercent="1"
                                            voldivpercent="0" backcolor="none" bordercolor="none"/>
                                    </div>
                                    <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                        dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="267,1">
                                        <div type="splitlayout" layoutstyle="toptobottom" backcolor="none" bordercolor="none"
                                            dock="fill" size="400,400" candragsplitter="true" splitmode="percentsize" splitterposition="200,1">
                                            <div type="custom" cid="mychart" name="chart7" cycle="1440" nativerefresh="true"
                                                candledivpercent="1" voldivpercent="0" backcolor="none" bordercolor="none"/>
                                            <div type="custom" cid="mychart" name="chart8" cycle="10080" nativerefresh="true"
                                                candledivpercent="1" voldivpercent="0" backcolor="none" bordercolor="none"/>
                                        </div>
                                        <div type="custom" cid="mychart" name="chart9" cycle="43200" nativerefresh="true"
                                            candledivpercent="1" voldivpercent="0" backcolor="none" bordercolor="none"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
        </body>
        </html>'''
renderFaceCat($gPaint, xml)
$gridStocks = findViewByName("gridStocks", $gPaint.views)
for i in 3..$gridStocks.columns.length - 1
	$gridStocks.columns[i].cellAlign = "right"
end
$gridStocks.selectedRowColor = "rgb(75,75,75)"
$gridStocks.alternateRowColor = "rgb(25,25,25)"
queryPrice("all")
strCode = "600000.SH"
strName = "浦发银行"
findViewsByType("mychart", $gPaint.views, $findMyCharts)
for i in 0..$findMyCharts.length - 1
	myChart = $findMyCharts[i]
	splitDiv = FCSplitLayoutDiv.new()
	splitDiv.layoutStyle = "toptobottom"
	splitDiv.size = FCSize.new(400, 400)
	splitDiv.backColor = "none"
	splitDiv.borderColor = "none"
	splitDiv.dock = "fill"
	addViewToParent(splitDiv, myChart)

	topDiv = FCLayoutDiv.new()
	topDiv.backColor = "none"
	topDiv.borderColor = "none"
	topDiv.layoutStyle = "lefttoright"
	topDiv.showHScrollBar = false
	addViewToParent(topDiv, splitDiv)

	bottomDiv = FCDiv.new()
	bottomDiv.backColor = "none"
	bottomDiv.borderColor = "none"
	addViewToParent(bottomDiv, splitDiv)

	splitDiv.firstView = topDiv
	splitDiv.secondView = bottomDiv

	splitter = FCView.new()
	splitter.parent = splitDiv
	if $gPaint.defaultUIStyle == "dark"
		splitter.backColor = "rgb(75,75,75)"
	elsif $gPaint.defaultUIStyle == "light"
		splitter.backColor = "rgb(150,150,150)"
	end
	splitter.borderColor = "none"
	splitter.paint = $gPaint
	splitDiv.views.append(splitter)
	splitDiv.splitter = splitter
	splitter.size = FCSize.new(400, 1)
	splitter.location = FCPoint.new(0, 30)
	if i == 0
		splitter.location = FCPoint.new(0, 0)
	end
	chart = FCChart.new()
	chart.leftVScaleWidth = 70
	chart.rightVScaleWidth = 70
	if i > 0
		chart.leftVScaleWidth = 0
	end
	chart.vScaleDistance = 35
	chart.hScalePixel = 11
	chart.hScaleHeight = 30
	chart.candlePaddingTop = 30
	chart.candlePaddingBottom = 20
	chart.volPaddingTop = 20
	chart.volPaddingBottom = 0
	chart.vScaleDistance = 35
	chart.dock = "fill"
	chart.font = "Default,12"
	chart.candleDivPercent = myChart.exAttributes["candledivpercent"].to_f
	chart.volDivPercent = myChart.exAttributes["voldivpercent"].to_f
	chart.indDivPercent = 0
	chart.text = strCode + " " + strName
	strCycle = myChart.exAttributes["cycle"]
	intCycle = strCycle.to_i
	if intCycle == 0
		chart.text += " 分时"
	elsif intCycle < 1440
		chart.text += " " + intCycle.to_s + "分钟"
	elsif intCycle == 1440
		chart.text += " 日线"
	elsif intCycle == 10080
		chart.text += " 周线"
	elsif intCycle == 43200
		chart.text += " 月线"
	end
	chart.allowDragChartDiv = true
	$charts.append(chart)
	addViewToParent(chart, bottomDiv)
	toBlackChart(chart, i)
	queryHistoryData(myChart, chart, strCode)
	cycles = []
	cycles.append("1")
	cycles.append("5")
	cycles.append("10")
	cycles.append("15")
	cycles.append("20")
	cycles.append("30")
	cycles.append("60")
	cycles.append("90")
	cycles.append("120")
	cycles.append("日")
	cycles.append("周")
	cycles.append("月")
	cycles.append("季")
	cycles.append("半")
	cycles.append("年")
	cyclesInts = []
	cyclesInts.append(1)
	cyclesInts.append(5)
	cyclesInts.append(10)
	cyclesInts.append(15)
	cyclesInts.append(20)
	cyclesInts.append(30)
	cyclesInts.append(60)
	cyclesInts.append(90)
	cyclesInts.append(120)
	cyclesInts.append(1440)
	cyclesInts.append(10080)
	cyclesInts.append(43200)
	cyclesInts.append(129600)
	cyclesInts.append(259200)
	cyclesInts.append(518400)
	for c in 0..cycles.length - 1
		cycleButton = FCButton.new()
		cycleButton.text = cycles[c]
		cycleButton.size = FCSize.new(27, 30)
		cycleButton.textColor = "rgb(200,200,200)"
		cycleButton.borderColor = "rgb(50,50,50)"
		cycleButton.backColor = "none"
		cycleButton.viewName = "cycle," + i.to_s + "," + cyclesInts[c].to_s
		addViewToParent(cycleButton, topDiv)
	end
end
queryNewData(strCode)
updateViewDefault($gPaint.views)
showWindow()

